crypto: support loading private keys through STORE loaders - #63949
Conversation
|
Review requested:
|
43f0d74 to
96c5081
Compare
ddd7eaf to
35bb771
Compare
I changed the feature shape quite a bit. Dismissing a stale review.
This comment was marked as resolved.
This comment was marked as resolved.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #63949 +/- ##
==========================================
- Coverage 90.29% 90.28% -0.02%
==========================================
Files 760 762 +2
Lines 247061 247317 +256
Branches 46584 46634 +50
==========================================
+ Hits 223096 223286 +190
- Misses 15437 15479 +42
- Partials 8528 8552 +24
🚀 New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
Changelog@@ -688,0 +689 @@
+/nix/store/qh8zlpfxnwrib9a549i1g7rhydn64510-libtasn1-4.21.0 (aarch64-darwin)
@@ -689,0 +691 @@
+/nix/store/xc8mgyg7afwgxkk63zspriizhh63frfr-libtasn1-4.21.0 (x86_64-darwin)
@@ -990,0 +993,4 @@
+/nix/store/r6iib8l02032bh1bh06sd34sh42q9d3h-node-pkcs11-softhsm (aarch64-darwin)
+/nix/store/kywy4qkq8xd3w3h3628i39x7cwlci229-node-pkcs11-softhsm (aarch64-linux)
+/nix/store/sc2gzl4cd4dyjyqw7hhk7z5bgcxv4lah-node-pkcs11-softhsm (x86_64-darwin)
+/nix/store/zrqjcrqjinnmqx8lngjpkrxy5f07h9xw-node-pkcs11-softhsm (x86_64-linux)
@@ -1149,0 +1156,5 @@
+/nix/store/s812sqfl0rvksypb4v0b37xpf214anyr-openssl-pkcs11.cnf (aarch64-darwin)
+/nix/store/z1vaf4krscysh8scdff9x2m9338g77ng-openssl-pkcs11.cnf (aarch64-linux)
+/nix/store/l6cdd0qpa02yrr9wbja8zjyxlm7711ss-openssl-pkcs11.cnf (x86_64-darwin)
+/nix/store/a7v4gj95mfrf8zbqcclg4d25axyib3m0-openssl-pkcs11.cnf (x86_64-linux)
+/nix/store/988jzin1q70hrqd1bgljryqgh3b67s4i-p11-kit-0.26.2 (aarch64-darwin)
@@ -1150,0 +1162 @@
+/nix/store/8sl4a8wad1b8lmc9ddnxbmh1x35a4dpl-p11-kit-0.26.2 (x86_64-darwin)
@@ -1338,0 +1351,4 @@
+/nix/store/17x34zhqssjfhjfza071xrp8000sgq7f-pkcs11-provider-1.2.0 (aarch64-darwin)
+/nix/store/cyklk079xsziqjhbf5329sw42w3c34lw-pkcs11-provider-1.2.0 (aarch64-linux)
+/nix/store/scy6w598p9s9cgysh9knlbmkrh3vfxdq-pkcs11-provider-1.2.0 (x86_64-darwin)
+/nix/store/hs4qkb0wkhlvzypi3hbwgmjzh9wq1zaf-pkcs11-provider-1.2.0 (x86_64-linux)
@@ -1512,0 +1529,4 @@
+/nix/store/03ni5f24xkxbzkd92wzv6wzyarky3frk-softhsm-2.7.0 (aarch64-darwin)
+/nix/store/wy7a65hjjf83v20nmqx86cqvfjgcx31x-softhsm-2.7.0 (aarch64-linux)
+/nix/store/39vmyzrbc5l3hzz9bj5kz3ji9g31024k-softhsm-2.7.0 (x86_64-darwin)
+/nix/store/9r8fsp6vvgjv7mkhcq32lip1jm542bnf-softhsm-2.7.0 (x86_64-linux) |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
CI shows a genuine windows clang test expectation mismatch |
Accept WHATWG URL objects in private-key inputs and load referenced keys through OpenSSL STORE loaders. Pass optional property queries and passphrases while preserving provider-owned EVP_PKEY objects for ordinary KeyObject and CryptoKey operations. Signed-off-by: Filip Skokan <panva.ip@gmail.com>
This comment was marked as outdated.
This comment was marked as outdated.
Changelog@@ -688,0 +689 @@
+/nix/store/qh8zlpfxnwrib9a549i1g7rhydn64510-libtasn1-4.21.0 (aarch64-darwin)
@@ -689,0 +691 @@
+/nix/store/xc8mgyg7afwgxkk63zspriizhh63frfr-libtasn1-4.21.0 (x86_64-darwin)
@@ -990,0 +993,4 @@
+/nix/store/r6iib8l02032bh1bh06sd34sh42q9d3h-node-pkcs11-softhsm (aarch64-darwin)
+/nix/store/kywy4qkq8xd3w3h3628i39x7cwlci229-node-pkcs11-softhsm (aarch64-linux)
+/nix/store/sc2gzl4cd4dyjyqw7hhk7z5bgcxv4lah-node-pkcs11-softhsm (x86_64-darwin)
+/nix/store/zrqjcrqjinnmqx8lngjpkrxy5f07h9xw-node-pkcs11-softhsm (x86_64-linux)
@@ -1149,0 +1156,5 @@
+/nix/store/s812sqfl0rvksypb4v0b37xpf214anyr-openssl-pkcs11.cnf (aarch64-darwin)
+/nix/store/z1vaf4krscysh8scdff9x2m9338g77ng-openssl-pkcs11.cnf (aarch64-linux)
+/nix/store/l6cdd0qpa02yrr9wbja8zjyxlm7711ss-openssl-pkcs11.cnf (x86_64-darwin)
+/nix/store/a7v4gj95mfrf8zbqcclg4d25axyib3m0-openssl-pkcs11.cnf (x86_64-linux)
+/nix/store/988jzin1q70hrqd1bgljryqgh3b67s4i-p11-kit-0.26.2 (aarch64-darwin)
@@ -1150,0 +1162 @@
+/nix/store/8sl4a8wad1b8lmc9ddnxbmh1x35a4dpl-p11-kit-0.26.2 (x86_64-darwin)
@@ -1338,0 +1351,4 @@
+/nix/store/17x34zhqssjfhjfza071xrp8000sgq7f-pkcs11-provider-1.2.0 (aarch64-darwin)
+/nix/store/cyklk079xsziqjhbf5329sw42w3c34lw-pkcs11-provider-1.2.0 (aarch64-linux)
+/nix/store/scy6w598p9s9cgysh9knlbmkrh3vfxdq-pkcs11-provider-1.2.0 (x86_64-darwin)
+/nix/store/hs4qkb0wkhlvzypi3hbwgmjzh9wq1zaf-pkcs11-provider-1.2.0 (x86_64-linux)
@@ -1512,0 +1529,4 @@
+/nix/store/03ni5f24xkxbzkd92wzv6wzyarky3frk-softhsm-2.7.0 (aarch64-darwin)
+/nix/store/wy7a65hjjf83v20nmqx86cqvfjgcx31x-softhsm-2.7.0 (aarch64-linux)
+/nix/store/39vmyzrbc5l3hzz9bj5kz3ji9g31024k-softhsm-2.7.0 (x86_64-darwin)
+/nix/store/9r8fsp6vvgjv7mkhcq32lip1jm542bnf-softhsm-2.7.0 (x86_64-linux) |
Changelog@@ -688,0 +689 @@
+/nix/store/qh8zlpfxnwrib9a549i1g7rhydn64510-libtasn1-4.21.0 (aarch64-darwin)
@@ -689,0 +691 @@
+/nix/store/xc8mgyg7afwgxkk63zspriizhh63frfr-libtasn1-4.21.0 (x86_64-darwin)
@@ -990,0 +993,4 @@
+/nix/store/r6iib8l02032bh1bh06sd34sh42q9d3h-node-pkcs11-softhsm (aarch64-darwin)
+/nix/store/kywy4qkq8xd3w3h3628i39x7cwlci229-node-pkcs11-softhsm (aarch64-linux)
+/nix/store/sc2gzl4cd4dyjyqw7hhk7z5bgcxv4lah-node-pkcs11-softhsm (x86_64-darwin)
+/nix/store/zrqjcrqjinnmqx8lngjpkrxy5f07h9xw-node-pkcs11-softhsm (x86_64-linux)
@@ -1149,0 +1156,5 @@
+/nix/store/s812sqfl0rvksypb4v0b37xpf214anyr-openssl-pkcs11.cnf (aarch64-darwin)
+/nix/store/z1vaf4krscysh8scdff9x2m9338g77ng-openssl-pkcs11.cnf (aarch64-linux)
+/nix/store/l6cdd0qpa02yrr9wbja8zjyxlm7711ss-openssl-pkcs11.cnf (x86_64-darwin)
+/nix/store/a7v4gj95mfrf8zbqcclg4d25axyib3m0-openssl-pkcs11.cnf (x86_64-linux)
+/nix/store/988jzin1q70hrqd1bgljryqgh3b67s4i-p11-kit-0.26.2 (aarch64-darwin)
@@ -1150,0 +1162 @@
+/nix/store/8sl4a8wad1b8lmc9ddnxbmh1x35a4dpl-p11-kit-0.26.2 (x86_64-darwin)
@@ -1338,0 +1351,4 @@
+/nix/store/17x34zhqssjfhjfza071xrp8000sgq7f-pkcs11-provider-1.2.0 (aarch64-darwin)
+/nix/store/cyklk079xsziqjhbf5329sw42w3c34lw-pkcs11-provider-1.2.0 (aarch64-linux)
+/nix/store/scy6w598p9s9cgysh9knlbmkrh3vfxdq-pkcs11-provider-1.2.0 (x86_64-darwin)
+/nix/store/hs4qkb0wkhlvzypi3hbwgmjzh9wq1zaf-pkcs11-provider-1.2.0 (x86_64-linux)
@@ -1512,0 +1529,4 @@
+/nix/store/03ni5f24xkxbzkd92wzv6wzyarky3frk-softhsm-2.7.0 (aarch64-darwin)
+/nix/store/wy7a65hjjf83v20nmqx86cqvfjgcx31x-softhsm-2.7.0 (aarch64-linux)
+/nix/store/39vmyzrbc5l3hzz9bj5kz3ji9g31024k-softhsm-2.7.0 (x86_64-darwin)
+/nix/store/9r8fsp6vvgjv7mkhcq32lip1jm542bnf-softhsm-2.7.0 (x86_64-linux) |
|
This is an AI-generated review looking for security vulnerabilities at the request of @panva. I found one issue that should be resolved before landing and two additional hardening issues:
I did not find a permission bypass, memory-safety issue, use-after-free, or provider-lifetime bug. The focused STORE, permission, and sign/verify tests passed, as did the reported CI matrix. Requesting changes for the issues above before this lands. |
Allow
crypto.createPrivateKey()and APIs that consume private keys, such ascrypto.sign(),crypto.privateDecrypt(),crypto.diffieHellman(), andcrypto.decapsulate(), to load private keys through configured OpenSSL STORE loaders using WHATWGURLobjects.This supports direct URL input:
It also supports object input with an optional passphrase or PIN and OpenSSL property query:
The provider implementing the STORE loader must already be loaded in Node.js' default OpenSSL library context, for example through OpenSSL configuration. This API does not load providers.
passphraseis forwarded to the loader as its passphrase or PIN.propertiesis an OpenSSL property query used to select the STORE loader; it is not appended to the URL and is distinct from provider-specific URI parameters.Why URL?
A
URLdistinguishes an external key reference from existing key material. Strings, buffers, typed arrays, and formatted objects retain their existing PEM, DER, JWK, and raw-key semantics. This avoids adding STORE loading to the key import/exportformatnamespace.URL input is accepted only in private-key contexts. A public key can be derived by first loading the private key and passing the resulting
KeyObjecttocrypto.createPublicKey().The resulting provider-backed key is an ordinary
KeyObjectand interoperates with existing private-key operations, key metadata, public-key derivation, andtoCryptoKey()where supported by the key algorithm and provider. Provider policy continues to control permitted operations and private-key exportability.The native STORE-loading path is available with OpenSSL >= 3.
Permission model
STORE loading adds the global
openssl.storepermission, enabled with--allow-openssl-storeand exposed through the runtime permission APIs:This permission grants broad authority to configured STORE loaders. Loaders may access files, devices, tokens, or the network, and that access is not constrained by the
fs.read,fs.write, ornetpermission scopes.This broad capability matches OpenSSL's behavior: STORE loaders perform their own I/O, and OpenSSL may try its file loader before another loader for opaque URIs.
When STORE access is denied, Node.js redacts the URI from the permission error resource and permission diagnostics.
Passphrases and errors
Credentials should be supplied through
passphraserather than embedded in the URI.If OpenSSL requests a passphrase and none was provided, Node.js throws
ERR_MISSING_PASSPHRASE, matching existing encrypted private-key import behavior. Incorrect passphrases and provider failures continue to surface as OpenSSL errors.Node.js redacts URIs from its own permission-denial errors. Errors reported by OpenSSL or a provider after loading begins may still include the URI.